<template>
    <div>
        <MsgList v-if="show" :barData="barData" :msgData="sellData" @msgClick="onMsgClick"/>
    </div>

  <ActionSheet v-model:show="action" title="订单详情">
    <CellGroup inset>
      <!-- 输入任意文本 -->
      <Field v-model="sellDetails.BuyTime" label="购买时间" />
      <Field v-model="sellDetails.PayTime" label="支付时间" />
      <Field v-model="sellDetails.ReceiveTime" label="收到时间" />
      <Field v-model="sellDetails.StatusText" label="当前状态" />
      <!-- 允许输入数字，调起带符号的纯数字键盘 -->
      <Field v-model="sellDetails.EPAmount" type="number" label="分数值" />
      <Field v-model="sellDetails.NetincomeStr" type="number" label="USDT" />

      <Field v-model="sellDetails.sell_NickName" label="卖家昵称" />
      <Field v-model="sellDetails.sell_MemberNo" label="卖家账户" />
      <Field v-model="sellDetails.sell_Usdt_Address" label="支付地址" />
    </CellGroup>
  </ActionSheet>
</template>

<script setup name="Msg">
import {markRaw, onBeforeMount, onMounted, reactive, ref} from 'vue';
import { Dialog, PullRefresh,ActionSheet,CellGroup,Field} from 'vant';
import MsgList from "@/components/MsgList/sell.vue"
import {doGet, doGetByAK} from "@/utils/request";
import {getToken} from "@/utils/auth";
import {messageTip} from "@/utils/messageTip";
import router from "@/router";

const barData = reactive([
  {
    title: '只保留上次任务信息,抢单后清空上次信息！',
    icon: 'comment-o'
  },
  {
    title: '发生异常请重新登录或联系开发者！',
    icon: 'info-o'
  }
]);

const data = reactive([
  { 
    userId: '9b54c39939c3776bd706ad315452cde8',
    avatar: './msg/avatar1.jpeg',
    nickName: 'Jasmine',
    newestMsg: '最近过得还好吗？',
    unReadCount: 2,
  },
  { 
    userId: '795d2d2f7711170a99958f8c8d195414',
    avatar: './msg/avatar2.jpeg',
    nickName: 'Amanda',
    newestMsg: 'vue-mobile-template这个模板简直了！',
    unReadCount: 0,
  },
  { 
    userId: 'c4dec0b791ad3df3d4e1bace20dc9c69',
    avatar: './msg/avatar3.jpeg',
    nickName: 'Christine',
    newestMsg: 'Hello~',
    dot: true
  },
]);

let sellData = reactive([])
let show = ref(false)
let account;
let userId;
let userKey;
let action = ref(false)
let sellDetails =  reactive({
    BuyTime:'',
    PayTime:'',
    ReceiveTime:'',
    StatusText:'',
    EPAmount:0,
    NetincomeStr: 0,
    sell_NickName: '',
    sell_MemberNo: '',
    sell_Usdt_Address: ''
});

function getSellList(){
  return doGet("getSells",{"key": account}).then(res =>{
    if (res.data.code === 200 && res.data.o){
      sellData.length = 0
      sellData.push(...res.data.o)
    }
  })
}

onBeforeMount(async () =>{
  let token = getToken()
  account = token.userAccount
  userId = token.userId
  userKey = token.userKey
  await getSellList()
  show.value = true
})

/**
 * sell信息内部的触发
 */

function onMsgClick(item){
  action.value = true
  getSellDetails(item.id,item.sokey)
}

/**
 * 获取订单详情
 */
function getSellDetails(sellId, soKey){
  doGetByAK("Public_EP_SellDetail",{
    sId:sellId,
    Sokey:soKey,
    key:userKey,
    UserID:userId
  }).then(res =>{
    if (!res.data.Error){
      let detail = res.data.Detail;
      sellDetails.BuyTime = detail.BuyTime
      sellDetails.PayTime = detail.PayTime
      sellDetails.ReceiveTime = detail.ReceiveTime
      sellDetails.StatusText = detail.StatusText
      sellDetails.EPAmount = detail.EPAmount
      sellDetails.NetincomeStr = detail.NetincomeStr
      sellDetails.sell_NickName = detail.Seller.NickName
      sellDetails.sell_MemberNo = detail.Seller.MemberNo
      sellDetails.sell_Usdt_Address = detail.Seller.Usdt.Address
    }else {
      messageTip("当前页已经失效！请重新登录获取最新信息！","warning")
    }
  })
}

/*
function onMsgRemove(item){
  Dialog({ message: `${item.nickName}被移除！` });
}
function onBarClick(item){
  Dialog({ message: `${item.title}被点击！` });
}*/
</script>

<style>
.content {
  padding: 16px 16px 260px;
}
</style>